<?php

/*
 * - Okek CMS
 * - create by Jg and Tito
 * - Okek Projects 2012
 * - CMS developed for free use
 * - More info http://habbo-dev.com
 */

class MySQL
{
    public $execute_querys = 0;
    public $last_query = '';
    public $connected = false;
    public $connection = null;
    private $mysql_config = null;
    private $error = false;
    
    private function Error() {
        $e = array("Error en el sistema de MySQL", mysql_errno(), mysql_error());
        LaunchError($e);
    }
    public function Initialize() {
        
        global $config, $error;
        
        if(!$error) {
            $this->mysql_config = $config[0];
        }
        
        $host = $this->mysql_config['host'];
        $port = $this->mysql_config['port'];
        $user = $this->mysql_config['user'];
        $password = $this->mysql_config['pass'];
        $database = $this->mysql_config['database'];

        $this->connection = mysql_connect("$host:$port", $user, $password) or $this->Error();
        mysql_select_db($database, $this->connection) or $this->Error();

        if(!$this->error) {
            $this->connected = true;
        }
    }
    
    public function query($sql) {
        global $error;
        
        if($error) {
            return false;
        }
        $this->last_query = $sql;
        
        if($this->connected) {
            $query = mysql_query($sql) or $this->Error();
            $this->execute_querys++;
            return $query;
        }
        else {
            return false;
        }
    }
    public function query_rows($sql) {
        if($this->connected) {
            $query = $this->query($sql);
            $count = mysql_num_rows($query);
            return ($count > 0 ? $count : false);
        }
        else {
            return false;
        }
    }
}
?>
